home *** CD-ROM | disk | FTP | other *** search
- C specifications explicitly say that atoi() and similar functions
- do not check for overflow. I found that I wanted to do so, so I wrote the
- four functions atoi_ex, atol_ex, atou_ex and atoul_ex, where the "ex"
- stands for "extended". They all check for overflow, and they all return
- a pointer the the character which terminates the number. In addition,
- they all strip leading white space characters from the number. They all
- return a result code which tells what happened.
-
- Because C doesn't check for overflow, I decided to do the main
- work in assembly language. The functions _natoi and _natol convert a
- string of digits to an unsigned int or an unsigned long, check for
- overflow and find the terminating character. They are not intended for
- use by themselves. I would like to hide them, but I don't know how to
- do it in this mixed language situation.
-
- ATOV_EX.C contains full instructions for using the functions.
-
- _NATOIL.ASM, which contains the source for the assembly programs,
- includes DOS.MAC, which is a Lattice C file which contains MACROS which
- generate most of the conventional information, such as GROUP and SEGMENT
- names, which MASM needs and which also contains some MACROS to interface
- with Lattice C. As a result, it probably won't work as is with any other
- compiler, but the changes should be routine. I am using Version 3.10. I
- don't have earlier versions available, so I can not be sure that all the
- MACROS in _NATOIL.ASM were defined.
-
- The files in ATOV_EX.ARC are:
- ATOV_EX.C Sources for atoi_ex, atol_ex, atou_ex and atoul_ex.
- ATOV_EX.H Function prototypes.
- ATOV_EXS.LIB Library which contains Lattice C small model
- ATOI_EX.OBJ, ATOL_EX.OBJ, ATOU_EX.OBJ, ATOUL_EX.OBJ,
- _NATOI.OBJ and _NATOL.OBJ.
- READ.ME This file.
- TATOV_EX.C Source for tests.
- _NATOIL.ASM Sources for _natoi and _natol.
-
- I hope these functions are useful. They are available for any
- non-commercial use. Of course, I am not responsible for any bad things
- they do to you.
-
- Lew Paper
- 8/31/86
-
- (Lew Paper and other fine programmers frequent
- Terrapin Station dBBS (networked) 2400/1200 24 hrs a day
- 612/623-0152 Minneapolis, MN)